﻿#region Using

using GameCommon.ComponentInterfaces;

using Menu.Components;

using GameComponent = GameCommon.Components.GameComponent;

#endregion

namespace Menu.Screens.MainMenu
{
    internal enum MainMenuState
    {
        Stay,

        FadeIn
    }

    internal class MainMenuTextFade : IAnimation
    {
        private const float FadeTimeOut = 0.01f;

        private const float FadeValue = 0.01f;

        private readonly MenuComponentBase component;

        private readonly double delay;

        private double elapsedTime;

        private MainMenuState state;

        public bool IsFinished { get; private set; }

        public MainMenuTextFade(GameComponent component, double delay)
        {
            this.component = (MenuComponentBase)component;
            this.delay = delay;
            this.state = MainMenuState.Stay;
        }

        public void Update(Microsoft.Xna.Framework.GameTime gameTime)
        {
            this.elapsedTime += gameTime.ElapsedGameTime.TotalSeconds;
            this.FadeIn();
        }

        private void FadeIn()
        {
            if (this.state == MainMenuState.Stay && this.elapsedTime > this.delay)
            {
                this.state = MainMenuState.FadeIn;
            }

            if (this.component.Opacity < 1 && this.elapsedTime > FadeTimeOut && this.state == MainMenuState.FadeIn)
            {
                this.component.Opacity += FadeValue;
                this.elapsedTime = 0;
            }
        }
    }
}